package xin.xihc.demo.model;

import lombok.Getter;
import lombok.Setter;
import xin.xihc.jba.annotation.*;
import xin.xihc.jba.core.JbaTemplate;
import xin.xihc.jba.demo.BaseModel;
import xin.xihc.jba.scan.tables.InitDataInterface;

import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Time;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @author xihc
 * @version 1.0
 * @date 2018年09月04日
 * @since 1.0
 */
@Getter
@Setter
@Table(value = "T_USER", remark = "用户信息测试表", order = 0)
@GroupIndex.List({@GroupIndex({"name", "age"}),
        @GroupIndex(type = Index.IndexType.Unique, value = {"id", "name", "age"})})
public class UserTest extends BaseModel implements InitDataInterface, Serializable {

    @Column(notNull = true, remark = "姓名", defaultValue = "未知", charset = Column.TableCharset.utf8mb4)
    private String name;

    @Column(notNull = true, remark = "年龄,测试Integer", defaultValue = "18")
    private Integer age;

    @Column(notNull = true, remark = "体重Kg,测试Double", precision = 2, defaultValue = "50.00")
    private Double weight;

    @Column(notNull = true, remark = "身高cm,测试Float", precision = 1)
    private Float height;

    @Column(value = "bir_d1", remark = "出生日期,测试java.util.Date", precision = 3, defaultValue = "CURRENT_TIMESTAMP(3)")
    @OnUpdateCurrentTimestamp
    private Date birDate;

    @Column(value = "bir_d2_0", remark = "出生日期,测试java.sql.Date", defaultValue = "2019-01-01")
    private java.sql.Date birDate2;

    @Column(value = "bir_d2_1", remark = "出生日期,测试java.sql.Time", defaultValue = "00:00:00")
    private java.sql.Time birTime;

    @Column(notNull = true, remark = "薪资,测试BigDecimal", defaultValue = "99999.00", length = 20, precision = 2)
    private BigDecimal salary;

    @Column(notNull = true, remark = "状态,测试枚举类型", defaultValue = "OFFLINE", length = 32)
    @Index
    private StatusEnum status;

    @Column(remark = "个人描述", length = 1024)
    private String description;

    @Column(remark = "操作员信息", length = 128)
    @JsonHandler
    private Operator operator = Operator.build();
    @Column(remark = "操作员信息", length = 256)
    @JsonHandler
    private List<Operator> operators = Arrays.asList(Operator.build(), Operator.build());

    @Override
    public void doInit(JbaTemplate jbaTemplate) {
        UserTest e = new UserTest();
        e.setName("张三");
        e.setAge(10);
        e.setBirDate(new Date());
        e.setBirDate2(new java.sql.Date(System.currentTimeMillis()));
        e.setBirTime(new Time(System.currentTimeMillis()));
        e.setCreateTime(new Date());
        e.setDescription(
                "个人简历是求职者给招聘单位发的一份简要介绍。包含自己的基本信息：姓名、性别、年龄、民族、籍贯、政治面貌、学历、联系方式，以及自我评价、工作经历、学习经历、荣誉与成就、求职愿望、对这份工作的简要理解等等。以简洁重点为最佳标准。");
        e.setHeight(180.0F);
        e.setSalary(new BigDecimal(8888));
        e.setStatus(StatusEnum.ONLINE);
        e.setWeight(65.00);
        jbaTemplate.insertModel(e);
    }

}
